<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->

<%
'on error resume next
if request("page")="" and request("fourpage")="" and request("fivepage")="" then
'第一步------------------------------------------------------------------------------------
apiurl="http://auctions.yahooapis.jp/AuctionWebService/V2/categoryTree?"
category=0
apilink=apiurl&"appid="&yahoo_daigou_apiid&"&category="&category&""
Set xml = Server.CreateObject("Microsoft.XMLHTTP") 
xml.Open "GET", apilink, False 
xml.Send 
Set xmlDom=Server.CreateObject("Microsoft.xmlDom") 
  xmlDom.Async=False 
  xmlDom.ValidateOnParse=False 
  xmlDom.Load(xml.responseXML) 
  If xmlDom.ReadyState>2 Then 
  Set item=xmlDom.getElementsByTagName("ChildCategory") 
  For res=0 To (item.Length-1)  
  Set CategoryId=item.Item(res).getElementsByTagName("CategoryId")'商品Id
  Set CategoryName=item.Item(res).getElementsByTagName("CategoryName")'商品名称
  CategoryId=CategoryId.Item(0).Text  '类别Id
  CategoryName=CategoryName.Item(0).Text  '类别名称
'重复id更新 ，不重复新增
set rsx=server.createobject("adodb.recordset")
sql="select * from y_daipaicat where CategoryId="&CategoryId&""
rsx.open sql,conn,1,3
if not rsx.eof then
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
else
rsx.addnew
rsx("CategoryId")=CategoryId
rsx("fid")=0
rsx("ParentCategoryId")=0
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
end if
next 
end if
'----------------------------------------------------------------------------------------------









'第二步---------------------------------------------------------------------------------------
'读取一级类别
set rslistx=server.CreateObject("adodb.recordset")
sql="select * from y_daipaicat where ParentCategoryId=0"
rslistx.open sql,conn,1,3
if not rslistx.eof then
do while not rslistx.eof
apiurl="http://auctions.yahooapis.jp/AuctionWebService/V2/categoryTree?"
category=rslistx("CategoryId")
apilink=apiurl&"appid="&yahoo_daigou_apiid&"&category="&category&""
Set xml = Server.CreateObject("Microsoft.XMLHTTP") 
xml.Open "GET", apilink, False 
xml.Send 
Set xmlDom=Server.CreateObject("Microsoft.xmlDom") 
  xmlDom.Async=False 
  xmlDom.ValidateOnParse=False 
  xmlDom.Load(xml.responseXML) 
  If xmlDom.ReadyState>2 Then 
  Set item=xmlDom.getElementsByTagName("ChildCategory") 
  For res=0 To (item.Length-1)  
  Set CategoryId=item.Item(res).getElementsByTagName("CategoryId")'商品Id
  Set CategoryName=item.Item(res).getElementsByTagName("CategoryName")'商品名称
  CategoryId=CategoryId.Item(0).Text  '类别Id
  CategoryName=CategoryName.Item(0).Text  '类别名称
'重复id更新 ，不重复新增
set rsx=server.createobject("adodb.recordset")
sql="select * from y_daipaicat where CategoryId="&CategoryId&""
rsx.open sql,conn,1,3
if not rsx.eof then
rsx("ParentCategoryId")=rslistx("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
else
rsx.addnew
rsx("CategoryId")=CategoryId
rsx("fid")=rslistx("id")
rsx("ParentCategoryId")=rslistx("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
end if
next 
end if
rslistx.movenext
loop
rslistx.close
set rslistx=nothing
end if	
response.Write "<script type=""text/javascript"">setTimeout('window.location=""daipaicat_yh.asp?page=1"";', 5000);</script>"
  response.Write "第1环节执行开始"
  response.End()
end if
'--------------------------------------------------------------------------------------------------------------





'第三步-----------------------------------------------------------------------------------------------
if request("page")<>"" then
'读取一级类别
Const MaxPerPage=10
  dim totalPut  
  dim CurrentPage
  dim TotalPages
  dim j
  dim sql
  dim onew
  dim twow
  if Not isempty(Request("page")) then
     currentPage=Cint(Request("page"))
  else
     currentPage=1
  end if 
  set rs=server.CreateObject("adodb.recordset")
  sql="SELECT * from y_daipaicat where ParentCategoryId in  (SELECT CategoryId from y_daipaicat where  ParentCategoryId=0)"
  rs.open sql,conn,1,3	 
  if rs.eof And rs.bof then
      Response.Write " <tr><td colspan='7' align='center' valign='top' class='diandian'>对不起，目前还没有信息！</td></tr></table><div>"   
  else
	  totalPut=rs.recordcount
  if currentpage<1 then
      currentpage=1
  end if
  if (currentpage-1)*MaxPerPage>totalput then
  if (totalPut mod MaxPerPage)=0 then
	  currentpage= totalPut \ MaxPerPage
  else
	  currentpage= totalPut \ MaxPerPage + 1
  end if
  end if
  if currentPage=1 then
      showContent
      showpage totalput,MaxPerPage,"daipaicat_yh.asp"
  else
  if (currentPage-1)*MaxPerPage<totalPut then
      rs.move  (currentPage-1)*MaxPerPage
      dim bookmark
      bookmark=rs.bookmark
      showContent
      showpage totalput,MaxPerPage,"daipaicat_yh.asp"
  else
	  currentPage=1
      showContent
      showpage totalput,MaxPerPage,"daipaicat_yh.asp"
  end if
  end if
  end if

  sub showContent
   dim i
	i=0
  do while not rs.eof
apiurl="http://auctions.yahooapis.jp/AuctionWebService/V2/categoryTree?"
category=rs("CategoryId")
apilink=apiurl&"appid="&yahoo_daigou_apiid&"&category="&category&""
Set xml = Server.CreateObject("Microsoft.XMLHTTP") 
xml.Open "GET", apilink, False 
xml.Send 
Set xmlDom=Server.CreateObject("Microsoft.xmlDom") 
  xmlDom.Async=False 
  xmlDom.ValidateOnParse=False 
  xmlDom.Load(xml.responseXML) 
  If xmlDom.ReadyState>2 Then 
  Set item=xmlDom.getElementsByTagName("ChildCategory") 
  For res=0 To (item.Length-1)  
  Set CategoryId=item.Item(res).getElementsByTagName("CategoryId")'商品Id
  Set CategoryName=item.Item(res).getElementsByTagName("CategoryName")'商品名称
  CategoryId=CategoryId.Item(0).Text  '类别Id
  CategoryName=CategoryName.Item(0).Text  '类别名称
'重复id更新 ，不重复新增
set rsx=server.createobject("adodb.recordset")
sql="select * from y_daipaicat where CategoryId="&CategoryId&""
rsx.open sql,conn,1,3
if not rsx.eof then
rsx("ParentCategoryId")=rs("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
else
rsx.addnew
rsx("CategoryId")=CategoryId
rsx("fid")=rs("id")
rsx("ParentCategoryId")=rs("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
end if
next 
end if
 i=i+1
 if i mod 1 = 0 then response.Write("")
  if i>=MaxPerPage then Exit Do
	rs.movenext
  loop
	rs.close
	set rs=nothing
End Sub    
Function showpage(totalnumber,maxperpage,filename)  
 Dim n 				
 If totalnumber Mod maxperpage=0 Then  
	n= totalnumber \ maxperpage  
 Else
	n= totalnumber \ maxperpage+1  
 End If
  if (CurrentPage+1) > n then
  response.Write "<script type=""text/javascript"">setTimeout('window.location=""daipaicat_yh.asp?fourpage=1"";', 5000);</script>"
  response.Write "进入四级更新，请不要关闭"
  response.End()
  else
  response.Write "<script type=""text/javascript"">setTimeout('window.location=""daipaicat_yh.asp?page="&(CurrentPage+1)&""";', 5000);</script>"
  response.Write "第"&(CurrentPage+1)&"环节执行完成，总共有"&n&"环节"
  response.End()
  end if
  End Function  
end if
'-------------------------------------------------------------------------------------------------







'第四步--------------------------------------------------------------------------------------
if request("fourpage")<>"" then
'读取一级类别
Const MaxPerPage2=10
  dim totalPut2  
  dim CurrentPage2
  dim TotalPages2
  dim j2
  dim sql2
  dim onew2
  dim twow2
  if Not isempty(Request("fourpage")) then
     currentPage2=Cint(Request("fourpage"))
  else
     currentPage2=1
  end if 
  set rs=server.CreateObject("adodb.recordset")
  sql="SELECT * from y_daipaicat where ParentCategoryId in  (SELECT CategoryId from y_daipaicat where ParentCategoryId in  (SELECT CategoryId from y_daipaicat where  ParentCategoryId=0))"
  rs.open sql,conn,1,3	 
  if rs.eof And rs.bof then
      Response.Write " <tr><td colspan='7' align='center' valign='top' class='diandian'>对不起，目前还没有信息！</td></tr></table><div>"   
  else
	  totalPut2=rs.recordcount
  if currentpage2<1 then
      currentpage2=1
  end if
  if (currentpage2-1)*MaxPerPage2>totalput2 then
  if (totalPut2 mod MaxPerPage2)=0 then
	  currentpage2= totalPut2 \ MaxPerPage2
  else
	  currentpage2= totalPut2 \ MaxPerPage2 + 1
  end if
  end if
  if currentPage2=1 then
      showContent2
      showpage2 totalput2,MaxPerPage2,"daipaicat_yh.asp"
  else
  if (currentPage2-1)*MaxPerPage2<totalPut2 then
      rs.move  (currentPage2-1)*MaxPerPage2
      'dim bookmark
      bookmark=rs.bookmark
      showContent2
      showpage2 totalput2,MaxPerPage2,"daipaicat_yh.asp"
  else
	  currentPage2=1
      showContent2
      showpage2 totalput2,MaxPerPage2,"daipaicat_yh.asp"
  end if
  end if
  end if
  sub showContent2
   dim i
	i=0
  do while not rs.eof
  apiurl="http://auctions.yahooapis.jp/AuctionWebService/V2/categoryTree?"
category=rs("CategoryId")
apilink=apiurl&"appid="&yahoo_daigou_apiid&"&category="&category&""
Set xml = Server.CreateObject("Microsoft.XMLHTTP") 
xml.Open "GET", apilink, False 
xml.Send 
Set xmlDom=Server.CreateObject("Microsoft.xmlDom") 
  xmlDom.Async=False 
  xmlDom.ValidateOnParse=False 
  xmlDom.Load(xml.responseXML) 
  If xmlDom.ReadyState>2 Then 
   Set item=xmlDom.getElementsByTagName("ChildCategory") 
  For res=0 To (item.Length-1)  
  Set CategoryId=item.Item(res).getElementsByTagName("CategoryId")'商品Id
  Set CategoryName=item.Item(res).getElementsByTagName("CategoryName")'商品名称
  CategoryId=CategoryId.Item(0).Text  '类别Id
  CategoryName=CategoryName.Item(0).Text  '类别名称
'重复id更新 ，不重复新增
set rsx=server.createobject("adodb.recordset")
sql="select * from y_daipaicat where CategoryId="&CategoryId&""
rsx.open sql,conn,1,3
if not rsx.eof then
rsx("ParentCategoryId")=rs("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
else
rsx.addnew
rsx("CategoryId")=CategoryId
rsx("fid")=rs("id")
rsx("ParentCategoryId")=rs("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
end if
next 
end if
 i=i+1
 if i mod 1 = 0 then response.Write("")
  if i>=MaxPerPage2 then Exit Do
	rs.movenext
  loop
	rs.close
	set rs=nothing
End Sub    
Function showpage2(totalnumber2,maxperpage2,filename2)  
 Dim n2				
 If totalnumber2 Mod maxperpage2=0 Then  
	n2= totalnumber2 \ maxperpage2  
 Else
	n2= totalnumber2 \ maxperpage2+1  
 End If
  if (CurrentPage2+1) > n2 then
  response.Write "<script type=""text/javascript"">setTimeout('window.location=""daipaicat_yh.asp?fivepage=1"";', 5000);</script>"
  response.Write "进入五级更新，请不要关闭"
  response.End()
  else
  response.Write "<script type=""text/javascript"">setTimeout('window.location=""daipaicat_yh.asp?fourpage="&(CurrentPage2+1)&""";', 5000);</script>"
  response.Write "第"&(CurrentPage2+1)&"环节执行完成，总共有"&n2&"环节"
  response.End()
  end if
  End Function  
end if
'----------------------------------------------------------------------------------------------







'第五步--------------------------------------------------------------------------------------
if request("fivepage")<>"" then
'读取一级类别
Const MaxPerPage5=10
  dim totalPut5  
  dim CurrentPage5
  dim TotalPages5
  dim j5
  dim sql5
  dim onew5
  dim twow5
  if Not isempty(Request("fivepage")) then
     currentPage5=Cint(Request("fivepage"))
  else
     currentPage5=1
  end if 
  set rs=server.CreateObject("adodb.recordset")
  sql="SELECT * from y_daipaicat where ParentCategoryId in  (SELECT CategoryId from y_daipaicat where ParentCategoryId in  (SELECT CategoryId from y_daipaicat where ParentCategoryId in  (SELECT CategoryId from y_daipaicat where  ParentCategoryId=0)))"
  rs.open sql,conn,1,3	 
  if rs.eof And rs.bof then
      Response.Write " <tr><td colspan='7' align='center' valign='top' class='diandian'>对不起，目前还没有信息！</td></tr></table><div>"   
  else
	  totalPut5=rs.recordcount
  if currentpage5<1 then
      currentpage5=1
  end if
  if (currentpage5-1)*MaxPerPage5>totalput5 then
  if (totalPut5 mod MaxPerPage5)=0 then
	  currentpage5= totalPut5 \ MaxPerPage5
  else
	  currentpage5= totalPut5 \ MaxPerPage5 + 1
  end if
  end if
  if currentPage5=1 then
      showContent5
      showpage5 totalput5,MaxPerPage5,"daipaicat_yh.asp"
  else
  if (currentPage5-1)*MaxPerPage5<totalPut5 then
      rs.move  (currentPage5-1)*MaxPerPage5
      'dim bookmark
      bookmark=rs.bookmark
      showContent5
      showpage5 totalput5,MaxPerPage5,"daipaicat_yh.asp"
  else
	  currentPage5=1
      showContent5
      showpage5 totalput5,MaxPerPage5,"daipaicat_yh.asp"
  end if
  end if
  end if
  sub showContent5
   dim i
	i=0
  do while not rs.eof
  apiurl="http://auctions.yahooapis.jp/AuctionWebService/V2/categoryTree?"
  category=rs("CategoryId")
  apilink=apiurl&"appid="&yahoo_daigou_apiid&"&category="&category&""
Set xml = Server.CreateObject("Microsoft.XMLHTTP") 
xml.Open "GET", apilink, False 
xml.Send 
Set xmlDom=Server.CreateObject("Microsoft.xmlDom") 
  xmlDom.Async=False 
  xmlDom.ValidateOnParse=False 
  xmlDom.Load(xml.responseXML) 
  If xmlDom.ReadyState>2 Then 
   Set item=xmlDom.getElementsByTagName("ChildCategory") 
  For res=0 To (item.Length-1)  
  Set CategoryId=item.Item(res).getElementsByTagName("CategoryId")'商品Id
  Set CategoryName=item.Item(res).getElementsByTagName("CategoryName")'商品名称
  CategoryId=CategoryId.Item(0).Text  '类别Id
  CategoryName=CategoryName.Item(0).Text  '类别名称
'重复id更新 ，不重复新增
set rsx=server.createobject("adodb.recordset")
sql="select * from y_daipaicat where CategoryId="&CategoryId&""
rsx.open sql,conn,1,3
if not rsx.eof then
rsx("ParentCategoryId")=rs("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
else
rsx.addnew
rsx("CategoryId")=CategoryId
rsx("fid")=rs("id")
rsx("ParentCategoryId")=rs("CategoryId")
rsx("CategoryName")=CategoryName
rsx.update
rsx.close
set rsx=nothing
end if
next 
end if
 i=i+1
 if i mod 1 = 0 then response.Write("")
  if i>=MaxPerPage5 then Exit Do
	rs.movenext
  loop
	rs.close
	set rs=nothing
End Sub    
Function showpage5(totalnumber5,maxperpage5,filename5)  
 Dim n5				
 If totalnumber5 Mod maxperpage5=0 Then  
	n5= totalnumber5 \ maxperpage5  
 Else
	n5= totalnumber5 \ maxperpage5+1  
 End If
  if (CurrentPage5+1) > n5 then
  response.Write "任务执行完成"
  response.End()
  else
  response.Write "<script type=""text/javascript"">setTimeout('window.location=""daipaicat_yh.asp?fivepage="&(CurrentPage5+1)&""";', 5000);</script>"
  response.Write "第"&(CurrentPage5+1)&"环节执行完成，总共有"&n5&"环节"
  response.End()
  end if
  End Function  
end if
%>